package com.dstz.base.rest.util;

import java.io.UnsupportedEncodingException;

import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.JSONObject;
import com.dstz.base.core.util.AppUtil;
import com.dstz.base.core.util.PropertyUtil;
import com.dstz.sys.util.SysPropertyUtil;

public class IPAddressUtil {

	/**
	 * 自定义查询IP归属地信息
	 */
	public static String getAddresses(String ip) throws UnsupportedEncodingException {
		RestTemplate restTemplate = AppUtil.getBean(RestTemplate.class);
		String baseUrl = SysPropertyUtil.getByAlias("api.url", PropertyUtil.getProperty("api.url", "http://api.xlongwei.com"));
		JSONObject json = restTemplate.getForObject(baseUrl+"/service/ip/region.json", JSONObject.class);
		return json==null ? null : json.getString("region");
	}

}
